﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace IronCow.UnitTests
{
    [TestFixture]
    public class RecurrenceConverterTests
    {
        [Test]
        public void TestEveryDay()
        {
            string i = "FREQ=DAILY;INTERVAL=1";
            string r = RecurrenceConverter.FormatRecurrence(i, true, DateFormat.Default);
            Assert.AreEqual("every day", r);
            Recurrence f = RecurrenceConverter.ParseRecurrence(r, DateFormat.Default);
            Assert.AreEqual(i, f.Repeat);
            Assert.IsTrue(f.IsEvery);
        }

        [Test]
        public void TestEveryMonday()
        {
            string i = "FREQ=WEEKLY;BYDAY=MO";
            string r = RecurrenceConverter.FormatRecurrence(i, true, DateFormat.Default);
            Assert.AreEqual("every Monday", r);
            Recurrence f = RecurrenceConverter.ParseRecurrence(r, DateFormat.Default);
            Assert.AreEqual(i, f.Repeat);
            Assert.IsTrue(f.IsEvery);
        }

        [Test]
        public void TestEveryFirstMondayOfTheMonth()
        {
            string i = "FREQ=MONTHLY;INTERVAL=1;BYDAY=MO";
            string r = RecurrenceConverter.FormatRecurrence(i, true, DateFormat.Default);
            Assert.AreEqual("every month on the 1st Monday", r);
            Recurrence f = RecurrenceConverter.ParseRecurrence(r, DateFormat.Default);
            Assert.AreEqual(i, f.Repeat);
            Assert.IsTrue(f.IsEvery);
        }

        [Test]
        public void TestEveryWeekEnd()
        {
            string i = "FREQ=WEEKLY;BYDAY=SA,SU";
            string r = RecurrenceConverter.FormatRecurrence(i, true, DateFormat.Default);
            Assert.AreEqual("every weekend", r);
            Recurrence f = RecurrenceConverter.ParseRecurrence(r, DateFormat.Default);
            Assert.AreEqual(i, f.Repeat);
            Assert.IsTrue(f.IsEvery);
        }
    }
}
